"""
列表的遍历
"""

def list_while_func():
    """
    使用while循环遍历列表
    :return: None
    """
    mylist = [1,2,3,4,5,6]
    index = 0
    while index < len(mylist):
        print(f"链表中下标为{index}的元素是：{mylist[index]}")
        index += 1
list_while_func()

def list_for_func():
    """
    使用for循环遍历列表
    :return: None
    """
    mylist = [1, 2, 3, 4, 5, 6]
    i = 0
    for i in mylist:
        print(i)
list_for_func()

# 练习（取出列表内的偶数）
mylist = [1,2,3,4,5,6,7,8,9,10]
even = []
for x in mylist:
    if x%2==0:
        even.append(x)
print(f"使用for循环获得的偶数列表是:{even}")

even = []
i = 0
while i<len(mylist):
    if mylist[i]%2==0:
        even.append(mylist[i])
    i+=1
print(f"使用while循环获得的偶数列表是:{even}")